package com.example.day1.util;

public class ToSayUtil {

    /**
     *
     * @param personNum 第几个人
     * @return 报数
     */
    public static String sayNumber(int personNum){
        String currentNumStr = String.valueOf(personNum),say = "";
        boolean remainder3,remainder5,remainder7;
        boolean contain3,contain5,contain7;
        contain3 = currentNumStr.contains("3");
        contain5 = currentNumStr.contains("5");
        contain7 = currentNumStr.contains("7");
        remainder3 = personNum % 3 == 0;
        remainder5 = personNum % 5 == 0;
        remainder7 = personNum % 7 == 0;
        if (contain7 && contain5) {
            //75
            say = "Fizz";
        } else if (contain7) {
            //包含7，不包含5；忽略被5整除
            if (remainder3 && remainder7) {
                say = "FizzBuzz";
            } else if (remainder3) {
                say = "Fizz";
            } else if (remainder7) {
                say = "Whizz";
            } else {
                say = currentNumStr;
            }
        } else if (contain5) {
            //包含5
            if (remainder5 && remainder7) {
                say = "BuzzWhizz";
            } else if (remainder5) {
                say = "Buzz";
            } else if (remainder7) {
                say = "Whizz";
            } else {
                say = currentNumStr;
            }
        }else if (contain3) {
            say = "Fizz";
        } else {
            say = multiple2Say(remainder3,remainder5,remainder7,personNum);
        }
        return say;
    }

    /**
     * 根据倍数2say
     * @param remainder3    3的倍数
     * @param remainder5    5的倍数
     * @param remainder7    7的倍数
     * @param personNum     第几个人
     * @return 2Say
     */
    public static String multiple2Say(boolean remainder3,boolean remainder5,boolean remainder7,int personNum) {
        String multiple2Say;
        //三个都是true
        if (remainder3 && remainder5 && remainder7) {
            multiple2Say = "FizzBuzzWhizz";
        } else if ((remainder3 && remainder5)
                || (remainder3 && remainder7)
                || (remainder5 && remainder7)) {
            //有一个false
            multiple2Say = "FizzBuzz";
        } else if (remainder3) {
            //有两个false ,其中 remainder3=true
            multiple2Say = "Fizz";
        } else if (remainder5) {
            //有两个false ,其中 remainder5=true
            multiple2Say = "Buzz";
        } else if (remainder7) {
            //有两个false ,其中 remainder7=true
            multiple2Say = "Whizz";
        } else {
            //三个都是false
            multiple2Say = "" + personNum;
        }
        return multiple2Say;
    }

}
